const request = require("request")
const md5 = require('md5')
exports.create = (router) => {
  router.post("/getWxId", (req, res) => {
    const code = req.body.code
    const appID = "wxc83e6252c81850f8"
    const Secret = "f1c908a9dffdc325c3fc943aeb47cf94"
    const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${appID}&secret=${Secret}&js_code=${code}&grant_type=authorization_code`
    request(url, (error, response, body) => {
      if (!error && response.statusCode === 200) {
        const data = JSON.parse(body)
        data.openid = md5(data.openid)
        res.send(data)
      } else {
        res.status(500).send({message:false})
      }
    })
  })
}
